package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture2D;

/**
 * This is the Main Class of your Game. You should only do initialization here.
 * Move your Logic into AppStates or Controls
 * @author normenhansen
 */
public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Node smith = (Node) assetManager.loadModel("Scenes/skinScene.j3o");
        PassUtil passUtil = new PassUtil(assetManager, renderManager);
        Texture2D renderTexture2D = passUtil.genRenderSceneTexture2D(smith, "LeePerrySmith-geom-0", assetManager.loadMaterial("Materials/SkinUVMaterial.j3m"), cam, cam.getWidth(), cam.getHeight(), 0x001);
        Texture2D blur1 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x002, 0x003, 512, 512, 1, 15, 2, 512);
        Texture2D blur2 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x004, 0x005, 512, 512, 1, 25, 3, 512);
        Texture2D blur3 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x006, 0x007, 512, 512, 1, 25, 4, 512);
        Material skinPass1 = assetManager.loadMaterial("Materials/SkinMaterial.j3m");
        skinPass1.setTexture("Blur1Map", renderTexture2D);
        skinPass1.setTexture("Blur2Map", blur1);
        skinPass1.setTexture("Blur3Map", blur2);
        skinPass1.setTexture("Blur4Map", blur3);
        smith.getChild("LeePerrySmith-geom-0").setMaterial(skinPass1);
        Node mainCamera = (Node) smith.getChild("mainCamera");
        cam.setLocation(mainCamera.getWorldTranslation());
        cam.setRotation(mainCamera.getWorldRotation());
        cam.setFrustumPerspective(45.0f, cam.getWidth() * 1.0f / cam.getHeight(), 0.01f, 500.0f);
        flyCam.setMoveSpeed(Float.parseFloat(mainCamera.getUserData("moveSpeed").toString()));

        rootNode.attachChild(smith);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}
